package com.cloud.quickcore.admin.controller;

import com.cloud.quickcommon.R;
import com.cloud.quickcore.admin.dto.LoginDto;
import com.cloud.quickcore.admin.dto.UserRegisterDto;
import com.cloud.quickcore.admin.service.SysUserService;
import com.cloud.quickcore.admin.vo.AdminLoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登陆、注册 --Controller
 * @author NiJo_H
 * @version 1.0
 * @date 2019/8/1 20:36
 */
@Api(tags = "后台-注册登陆")
@RestController
@Slf4j
public class LoginController {
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "注册用户")
    @PostMapping("/sign")
    public R<Void> sign(@RequestBody UserRegisterDto dto){
        log.info("sign,注册用户操作，接收参数{}",dto);
        sysUserService.save(dto);
        return R.ok();
    }

    @ApiOperation(value = "登陆用户")
    @PostMapping("/login")
    public R<AdminLoginVo> login(@RequestBody LoginDto dto){
        log.info("login,登陆操作,接收参数{}",dto);
        return R.ok(sysUserService.login(dto));
    }
}
